<template>
  <div class="data-authority">
    <!-- <je-panel>
      <je-panel-item region="left" v-bind="options.left">
        <je-tree
          ref="treeview"
          class="table-treeView"
          :search="true"
          border="outer"
          :tree-config="{
            trigger: 'cell-dblclick',
            rowField: 'id',
            parentField: 'parent',
          }"
          :loading="loading"
          size="mini"
          :data="treeData"
          @current-change="doShowWin"
        >
        </je-tree
      ></je-panel-item>
      <je-panel-item>
        <div v-if="showDialog" class="panel-default">
          <OpenDialog
            :key="funcId"
            v-model:visible="showDialog"
            :func-id="funcId"
            :func-code="funcCode"
          />
        </div>
      </je-panel-item>
    </je-panel> -->
  </div>
</template>
<script>
  import {
    defineComponent /*  onMounted, reactive, toRefs, defineAsyncComponent, ref */,
  } from 'vue';

  /* import { Panel, Tree } from '@jecloud/ui';

  import { loadGridTreeDataApi } from '@/api/authorization'; */

  import { showDataAuthorityWin } from '@/hooks/use-data-authority';

  import { useMicroStore } from '@common/store/micro-store';

  export default defineComponent({
    name: 'DataAuthority',
    components: {
      /* OpenDialog: defineAsyncComponent(() => import('./open-dialog/index.vue')),
      JePanel: Panel,
      JePanelItem: Panel.Item,
      JeTree: Tree, */
    },
    setup() {
      // 获取子应用store
      const microStore = useMicroStore();

      // 注册事件
      microStore.on('data-authority-init', ({ funcCode, funcId }, fn) => {
        // ...业务逻辑
        showDataAuthorityWin({ funcCode, funcId }, fn);
      });

      /* const options = {
        left: {
          size: 232,
        },
      };
      // 是否显示弹框
      const showDialog = ref(false);

      const treeData = ref([]);
      const treeview = ref('treeview');
      const loading = ref(false);
      const funcId = ref('6jhEYhu9KKEUKw10utO'); // 功能id
      const funcCode = ref('JE_PFCS_CSB1'); // 功能id

      // //得到左侧tree数据
      const getTreeData = () => {
        loading.value = true;
        loadGridTreeDataApi({
          tableCode: 'JE_CORE_FUNCINFO',
          rootId: 'ROOT',
          SY_PRODUCT_ID: 'yxljlUCJu9fcxX7tRAi111',
          j_query: {
            order: [{ code: 'SY_ORDERINDEX', type: 'ASC' }],
            custom: [
              {
                type: 'and',
                value: [
                  { type: 'like', code: 'FUNCINFO_FUNCNAME', value: '', cn: 'or' },
                  { type: 'like', code: 'FUNCINFO_FUNCCODE', value: '', cn: 'or' },
                ],
              },
            ],
          },
        }).then((res) => {
          treeData.value = res.children;
          loading.value = false;
        });
      };

      // // 点击树型
      const handlerSelect = () => {
        const row = treeview.value.getCurrentRecord();
        if (row && row?.JE_CORE_FUNCINFO_ID && row?.nodeInfoType === 'FUNC') {
          funcId.value = row.JE_CORE_FUNCINFO_ID;
          funcCode.value = row.FUNCINFO_FUNCCODE;
          showDialog.value = true;
        }
      };

      onMounted(() => {
        getTreeData();
      });

      // // 集成代码
      const doShowWin = () => {
        const row = treeview.value.getCurrentRecord();
        if (row && row?.JE_CORE_FUNCINFO_ID && row?.nodeInfoType === 'FUNC') {
          funcId.value = row.JE_CORE_FUNCINFO_ID;
          funcCode.value = row.FUNCINFO_FUNCCODE;
        }
        showDataAuthorityWin({ funcCode, funcId }, () => {});
      }; */

      /* const state = reactive({
        options,
        treeData,
        loading,
        treeview,
        funcId,
        funcCode,
        showDialog,
      }); */

      return {
        /* doShowWin, handlerSelect, ...toRefs(state)  */
      };
    },
  });
</script>

<style lang="less" scoped>
  .data-authority {
    width: 100%;
    height: 100%;
    background: #ffffff;
    // padding: 20px;
    // margin: 10px auto;
    :deep(.table-treeView .ant-input-affix-wrapper) {
      height: 40px;
    }
    :deep(.table-treeView .vxe-table--render-default .vxe-table--border-line) {
      border-top: 1px solid #ffffff !important;
    }
  }
</style>
